/**
 * 流程定义管理 API
 */
import type { ProcessDefinition, ProcessDefinitionQuery } from './types';

import { requestClient } from '../request';

/**
 * 获取流程定义列表
 */
export async function getProcessDefinitionListApi(
  params: ProcessDefinitionQuery,
) {
  return requestClient.get<{
    list: ProcessDefinition[];
    total: number;
    pageNum: number;
    pageSize: number;
  }>('/workflow/api/definition/list', { params });
}

/**
 * 获取流程定义详情
 */
export async function getProcessDefinitionDetailApi(id: string) {
  return requestClient.get<ProcessDefinition>(
    `/workflow/api/definition/${id}`,
  );
}

/**
 * 获取流程定义的BPMN XML
 */
export async function getProcessDefinitionBpmnApi(id: string) {
  return requestClient.get<{ bpmnXml: string }>(
    `/workflow/api/definition/${id}/bpmn`,
  );
}

/**
 * 获取流程定义的流程图（SVG）
 */
export async function getProcessDefinitionDiagramApi(id: string) {
  return requestClient.get<string>(`/workflow/api/definition/${id}/diagram`, {
    responseType: 'text',
  });
}

/**
 * 激活流程定义
 */
export async function activateProcessDefinitionApi(id: string) {
  return requestClient.post(`/workflow/api/definition/${id}/activate`);
}

/**
 * 挂起流程定义
 */
export async function suspendProcessDefinitionApi(id: string) {
  return requestClient.post(`/workflow/api/definition/${id}/suspend`);
}

/**
 * 删除流程定义
 */
export async function deleteProcessDefinitionApi(id: string) {
  return requestClient.delete(`/workflow/api/definition/${id}`);
}

/**
 * 转换为流程模型
 */
export async function convertToModelApi(id: string) {
  return requestClient.post(`/workflow/api/definition/${id}/convert-to-model`);
}

